package com.atguigu.dao.impl;

import com.atguigu.dao.OrderDao;
import com.atguigu.pojo.Order;

import java.util.List;

public class OrderDaoImpl extends baseDao<Order> implements OrderDao {

    @Override
    public void saveOrder(Order order) {
        String sql = "insert into t_order values(?,?,?,?,?)";
        update(sql, order.getOrder_id(), order.getCreate_time(), order.getPrice(), order.getStatus(), order.getUser_id());
    }

    @Override
    public List<Order> queryOrdersAll() {
        String sql = "SELECT order_id, create_time, price, status, user_id FROM t_order;";
        return getForList(sql);
    }

    @Override
    public List<Order> queryOrdersById(int userId) {
        String sql = "SELECT order_id, create_time, price, status, user_id FROM t_order where user_id = ?";
        return getForListLimit(sql, userId);
    }

    @Override
    public void deleteOrderById(String order_id) {
        String sql = "delete from t_order where order_id = ?";
        update(sql, order_id);
    }
}
